package com.matrix.java.chap_03;

import java.util.Scanner;

/*
    商业：检查 ISBN-10
 */
public class Ex3_09 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("Enter the first 9 digits of an ISBN as integer: ");
        String numString = input.next();
        int num = Integer.parseInt(numString);
        int num1 = num % 10;
        int num2 = num / 10 %10;
        int num3 = num / 100 % 10;
        int num4 = num / 1000 % 10;
        int num5 = num / 10000% 10;
        int num6 = num / 100000 % 10;
        int num7 = num / 1000000 % 10;
        int num8 = num / 10000000 % 10;
        int num9 = num / 100000000 % 10;
        int sum = (num9 * 1 + num8 * 2 + num7 * 3 + num6 * 4 + num5 * 5 + num4 * 6 + num3 * 7 + num2 * 8 + num1 * 9) % 11;
        if (sum == 10) {
            System.out.println(numString + "X");
        }else {
            System.out.println(numString + sum);
        }
        input.close();
    }
}
